package site.zhouinfo.scanfiletime;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 扫描文件修改时间
 *
 * @author zhou
 * @create 2017-10-18 23:45
 * @email zhouinfo@qq.com
 * @blog blog.zhouinfo.site
 */
public class ScanFileModificationTime {

    List<FileInfo> fileInfoList = new ArrayList<>(3000);

    public static void main(String[] args) throws IOException {
        ScanFileModificationTime scan = new ScanFileModificationTime();
        //scan.scanFile(new File("E:\\gzpykj\\webapp\\chps"));
        scan.scanFile(new File("E:\\chps\\GDhuizhoushi\\build\\chps"));
        Collections.sort(scan.fileInfoList);


        FileWriter fw = new FileWriter("E:\\123.txt");
        for (FileInfo fileInfo : scan.fileInfoList) {
            fw.write(fileInfo.toString());
        }
        fw.close();
    }

    private void scanFile(File f) {
        if (f.isFile()) {
            fileInfoList.add(new FileInfo(f.toString(), f.lastModified()));
        }
        if (f.isDirectory()) {
            File[] files = f.listFiles();
            for (File file : files) {
                scanFile(file);
            }
        }
    }
}
